from xen.xend.server.DevController import DevController
+from xen.xend.XendLogging import log
from xen.xend.XendError import VmError
import xen.xend
"--title", self.vm.getName() ]
t = config.get("type", None)
if t == "vnc":
+ passwd = None
+ if config.has_key("vncpasswd"):
+ passwd = config["vncpasswd"]
+ else:
+ passwd = xen.xend.XendRoot.instance().get_vncpasswd_default()
+ if not(passwd is None or passwd == ""):
+ self.vm.storeVm("vncpasswd", passwd)
+ log.debug("Stored a VNC password for vfb access")
+ else:
+ log.debug("No VNC passwd configured for vfb access")
+
# Try to start the vnc backend
args = [xen.util.auxbin.pathTo("xen-vncfb")]
if config.has_key("vncunused"):
use="""Add a physical USB port to a domain, as specified by the path
to that port. This option may be repeated to add more than one port.""")
-gopts.var('vfb', val="type={vnc,sdl},vncunused=1,vncdisplay=N,vnclisten=ADDR,display=DISPLAY,xauthority=XAUTHORITY",
+gopts.var('vfb', val="type={vnc,sdl},vncunused=1,vncdisplay=N,vnclisten=ADDR,display=DISPLAY,xauthority=XAUTHORITY,vncpasswd=PASSWORD",
fn=append_value, default=[],
use="""Make the domain a framebuffer backend.
The backend type should be either sdl or vnc.
d['type'] = 'sdl'
for (k,v) in d.iteritems():
if not k in [ 'vnclisten', 'vncunused', 'vncdisplay', 'display',
- 'xauthority', 'type' ]:
+ 'xauthority', 'type', 'vncpasswd' ]:
err("configuration option %s unknown to vfbs" % k)
config.append([k,v])
if not d.has_key("display") and os.environ.has_key("DISPLAY"):
last_y = y;
}
-static void xenstore_write_vncport(int port, int domid)
+static void xenstore_write_vncport(struct xs_handle *xsh, int port, int domid)
{
- char *buf = NULL, *path;
+ char *buf, *path;
char portstr[10];
- struct xs_handle *xsh = NULL;
-
- xsh = xs_daemon_open();
- if (xsh == NULL)
- return;
path = xs_get_domain_path(xsh, domid);
if (path == NULL) {
}
+static int xenstore_read_vncpasswd(struct xs_handle *xsh, int domid, char *pwbuf, int pwbuflen)
+{
+ char buf[256], *path, *uuid = NULL, *passwd = NULL;
+ unsigned int len, rc = 0;
+
+ if (xsh == NULL) {
+ return -1;
+ }
+
+ path = xs_get_domain_path(xsh, domid);
+ if (path == NULL) {
+ fprintf(stderr, "xs_get_domain_path() error\n");
+ return -1;
+ }
+
+ snprintf(buf, 256, "%s/vm", path);
+ uuid = xs_read(xsh, XBT_NULL, buf, &len);
+ if (uuid == NULL) {
+ fprintf(stderr, "xs_read(): uuid get error\n");
+ free(path);
+ return -1;
+ }
+
+ snprintf(buf, 256, "%s/vncpasswd", uuid);
+ passwd = xs_read(xsh, XBT_NULL, buf, &len);
+ if (passwd == NULL) {
+ free(uuid);
+ free(path);
+ return rc;
+ }
+
+ strncpy(pwbuf, passwd, pwbuflen-1);
+ pwbuf[pwbuflen-1] = '\0';
+
+ fprintf(stderr, "Got a VNC password read from XenStore\n");
+
+ passwd[0] = '\0';
+ snprintf(buf, 256, "%s/vncpasswd", uuid);
+ if (xs_write(xsh, XBT_NULL, buf, passwd, len) == 0) {
+ fprintf(stderr, "xs_write() vncpasswd failed\n");
+ rc = -1;
+ }
+
+ free(passwd);
+ free(uuid);
+ free(path);
+
+ return rc;
+}
+
static void vnc_update(struct xenfb *xenfb, int x, int y, int w, int h)
{
rfbScreenInfoPtr server = xenfb->user_data;
char portstr[10];
char *endp;
int r;
+ struct xs_handle *xsh;
+ char vncpasswd[1024];
+
+ vncpasswd[0] = '\0';
while ((opt = getopt_long(argc, argv, "d:p:t:u", options,
NULL)) != -1) {
exit(1);
}
+ xsh = xs_daemon_open();
+ if (xsh == NULL) {
+ fprintf(stderr, "cannot open connection to xenstore\n");
+ exit(1);
+ }
+
+
+ if (xenstore_read_vncpasswd(xsh, domid, vncpasswd, sizeof(vncpasswd)/sizeof(char)) < 0) {
+ fprintf(stderr, "cannot read VNC password from xenstore\n");
+ exit(1);
+ }
+
+
server = rfbGetScreen(&fake_argc, fake_argv,
xenfb->width, xenfb->height,
8, 3, xenfb->depth / 8);
if (unused)
server->autoPort = true;
+ if (vncpasswd[0]) {
+ char **passwds = malloc(sizeof(char**)*2);
+ if (!passwds) {
+ fprintf(stderr, "cannot allocate memory (%s)\n", strerror(errno));
+ exit(1);
+ }
+ fprintf(stderr, "Registered password\n");
+ passwds[0] = vncpasswd;
+ passwds[1] = NULL;
+
+ server->authPasswdData = passwds;
+ server->passwordCheck = rfbCheckPasswordByList;
+ } else {
+ fprintf(stderr, "Running with no password\n");
+ }
server->serverFormat.redShift = 16;
server->serverFormat.greenShift = 8;
server->serverFormat.blueShift = 0;
rfbRunEventLoop(server, -1, true);
- xenstore_write_vncport(server->port, domid);
+ xenstore_write_vncport(xsh, server->port, domid);
for (;;) {
FD_ZERO(&readfds);